<?php
$this->breadcrumbs=array(
	'Genealogy',
);
?>
<div>
  <a href="<?php echo Yii::app()->request->baseUrl;?>/?r=Members/admin"> GO BACK TO MEMBERS </a> 
</div>
<?php
#defaults to member no 1
if ( !isset($_GET['id']) || !$_GET['id'] )
   $_GET['id'] =1; 

$parent  = $this->getMember( $_GET['id'] );

if ( !$parent ) {
	echo "<h1> Member not found! </h1>";
}
else {
	
	$sponsor = $this->getMember( $parent['sponsor_id'] );
	
    $parent_header  = '['.$parent['member_id'].'] '.$parent['last_name'].', '.$parent['first_name'];
    $parent_header .= ' '.$parent['middle_name'];
	
	$children = $this->getChildren( $_GET['id'] );
	
	$l_downlines = array();
	$r_downlines = array();
	
	//print_r( $children );
	
	if ( isset($children['left']) ) {
	  $data = $children['left'];	
	  array_push( $l_downlines, $data );
	  $this->getDownlines( $data['member_id'], $l_downlines );
	}
	
	if ( isset($children['right']) ) {
	  $data = $children['right'];	
	  array_push( $r_downlines, $data );
	  $this->getDownlines( $data['member_id'], $r_downlines );
	}

    $l_total = count($l_downlines);
	$r_total = count($r_downlines);
	//print_r( $l_downlines );
	//print_r( $r_downlines );
	
	if ( isset($sponsor['member_id']) ) { 
	    $sponsor_header  = '['.$sponsor['member_id'].'] '.$sponsor['last_name'].', '.$sponsor['first_name'];
        $sponsor_header .= ' '.$sponsor['middle_name'];
		
		$sponsor_url = 'index.php?r=Genealogy&id='.$sponsor['member_id']; 
	?>
        <div style="text-align:right;"> 
          <strong> SPONSOR: </strong>
          <a href="<?php echo $sponsor_url?>"> <?php echo $sponsor_header?> </a>
        </div>
    <?php
	}
?>
<link rel="stylesheet" type="text/css" href="<?php echo Yii::app()->request->baseUrl;?>/assets/4d2e049c/gridview/styles.css" />
<center>
  <h1> <?php echo $parent_header?></h1>
  
  <div> 
     <a href="<?php echo Yii::app()->request->baseUrl;?>/?r=Genealogy/excelGenealogy&id=<?php echo$_GET['id']?>"> Download Excel </a>
  </div>
   
  <div class="grid-view">
      <table>
      <tr>
         <th style="text-align:center"> <h3>LEFT GROUP (<?php echo $l_total?>)</h3> </th>
         <th style="text-align:center"> <h3>RIGHT GROUP (<?php echo $r_total?>)</h3> </th> 
      </tr>
      <tr>
         <td style="vertical-align:top;"> 
            <table class="items">
              <tr><th width="1">ID</th><th>Name</th><th width="1">Sponsor</th></tr>
              <?php 
			  $class = "odd";
			  foreach ( $l_downlines as $member ) { ?>
                  <tr class="<?php echo $class?>">
                     <td><?php echo $member['member_id']?> </td>
                     <td>
                         <a href="index.php?r=Genealogy&id=<?php echo $member['member_id']?>">
					     <?php echo $member['last_name'].' '.$member['first_name']?>
                         </a> 
                     </td>
                     <td>
                         <a href="index.php?r=Genealogy&id=<?php echo $member['sponsor_id']?>">
					     <?php echo $member['sponsor_id']?> 
                         </a>
                     </td>
                  </tr>
                  <?php 
                  if ( $class=='odd' )
                    $class = 'even';
                  else
                    $class = 'odd';
			  } ?>
            </table> 
         </td>
         <td style="vertical-align:top;"> 
            <table class="items">
              <tr><th width="1">ID</th><th>Name</th><th width="1">Sponsor</th></tr>
              <?php 
			  $class = "odd";
			  foreach ( $r_downlines as $member ) { ?>
                  <tr class="<?php echo $class?>">
                     <td><?php echo $member['member_id']?> </td>
                     <td>
                         <a href="index.php?r=Genealogy&id=<?php echo $member['member_id']?>">
					     <?php echo $member['last_name'].' '.$member['first_name']?>
                         </a> 
                     </td>
                     <td>
                         <a href="index.php?r=Genealogy&id=<?php echo $member['sponsor_id']?>">
					     <?php echo $member['sponsor_id']?> 
                         </a>
                     </td>
                  </tr>
              <?php 
                  if ( $class=='odd' )
                    $class = 'even';
                  else
                    $class = 'odd';
			  } ?>
            </table> 
         </td> 
      </tr>
      </table>
  </div>
</center>

<div>
  <a href="<?php echo Yii::app()->request->baseUrl;?>/?r=Members/admin"> GO BACK TO MEMBERS </a> 
</div>
<?php } ?>


